﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace ATPlatforms.RabbitSkin.Serializers
{
    public class JSONMessageSerializer<T> : ISerializeMessages<T>
    {
        public byte[] SerializeMessage(T message)
        {
            string output = JsonConvert.SerializeObject(message);
            return Encoding.UTF8.GetBytes(output);
        }

        public T DeSerializeMessage(byte[] message)
        {
            string input = Encoding.UTF8.GetString(message);
            return (T)JsonConvert.DeserializeObject(input, typeof(T));
        }
    }
}
